package com.helploan.helploangenerator;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

import java.util.ArrayList;

public class DongbaoGenerator {
	public static void main(String[] args) {
		ArrayList<String> list = new ArrayList<>();
		list.add("t_carousel_image");
		for (String str : list) {
			newCode(str);
		}
	}

	private static void newCode(String tableName) {
		// 构建一个代码生成对象
		AutoGenerator mpg = new AutoGenerator();
		// 1. 全局配置
		GlobalConfig gc = new GlobalConfig();
		gc.setOutputDir("D:\\WBCX\\college\\college-common\\college-common-base\\src\\main\\java\\com\\college\\common\\pojo\\CarouselImage");
		gc.setAuthor("小C工作室");
		gc.setOpen(false);//打开目录
		gc.setFileOverride(true);//是否覆盖
		gc.setIdType(IdType.AUTO);//设置主键策略
		gc.setBaseResultMap(true);//生成基本ResultMap
		gc.setBaseColumnList(true);//生成基本ColumnList
		gc.setServiceName("%sService");//去掉服务默认前缀
		gc.setDateType(DateType.ONLY_DATE);//设置时间类型
		gc.setSwagger2(true);
		mpg.setGlobalConfig(gc);

		// 设置指定数据库
		DataSourceConfig dsc = new DataSourceConfig();
		dsc.setUrl("jdbc:mysql://110.41.136.218:3306/campus_secondhand?serverTimezone=PRC&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false");
		dsc.setDriverName("com.mysql.cj.jdbc.Driver");
		dsc.setUsername("campus_secondhand");
		dsc.setPassword("rXB8jndDSN3DFLFd");
		dsc.setDbType(DbType.MYSQL);
		mpg.setDataSource(dsc);

		// 包设置
		PackageConfig pc = new PackageConfig();
		pc.setParent("com.college");
		pc.setEntity("pojo.ao");
		pc.setMapper("mapper");
		pc.setXml("xml");
		pc.setController("controller");
		pc.setService("service");
		pc.setServiceImpl("service.impl");
		mpg.setPackageInfo(pc);

		// 策略配置
		StrategyConfig strategy = new StrategyConfig();
		strategy.setInclude(tableName);//表名
		strategy.setNaming(NamingStrategy.underline_to_camel);// 下划线转他驼峰
		strategy.setColumnNaming(NamingStrategy.underline_to_camel);// 列 下划线转脱发
		strategy.setEntityLombokModel(true);//lombok 开启

		// 自动填充
		strategy.setTablePrefix("t_");

		//乐观锁
		strategy.setVersionFieldName("version");

		strategy.setRestControllerStyle(true);
		strategy.setControllerMappingHyphenStyle(true);// localhost:xxx/hello_2

		mpg.setStrategy(strategy);

		mpg.execute();
	}
}
